﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Krilib.Bridges;
using Krilib.Control;
using System.Windows.Forms;

namespace Krile.Cores
{
    public class ControlManager : IControlManager
    {
        Dictionary<string,Type> methodDict = new Dictionary<string,Type>();

        internal IInputMethod LookupMethod(string identify)
        {
            if(!methodDict.ContainsKey(identify))
                throw new ApplicationException("ID:\"" + identify + "\" not existed.");
            return Activator.CreateInstance(methodDict[identify]) as IInputMethod;
        }

        public void RegistInputMethod(IInputMethod method)
        {
            if (!(method is UserControl))
                throw new Exception("argument can't cast to UserControl.");
            if (method.IdentifyString == null)
                throw new Exception("Identify String hadn't override or set unarrowed value.(method.IdentifyString returned null.)");
            if (methodDict.ContainsKey(method.IdentifyString))
                throw new ApplicationException("Identify string duplicated.");
            methodDict.Add(method.IdentifyString, method.GetType());
        }
    }
}
